package com.liruo.springframework.core.aop.springinterceptor;

import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.NameMatchMethodPointcut;
import org.springframework.aop.support.RootClassFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DirectAdvisorConfiguration {
  @Bean
  public DefaultPointcutAdvisor myNameMatchMethodAdvisor() {
    NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut();
    pointcut.setClassFilter(new RootClassFilter(CommonTarget.class));
    pointcut.addMethodName("common");
    return new DefaultPointcutAdvisor(
        pointcut,
        new SimpleTraceMethodInterceptor("myNameMatchMethodAdvisor")
    );
  }

  @Bean
  public DefaultPointcutAdvisor myAspectJExpressionAdvisor() {
    AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
    pointcut.setExpression("execution(String com.liruo.springframework.core.aop.springinterceptor.CommonTarget.common(..))");
    return new DefaultPointcutAdvisor(
        pointcut,
        new SimpleTraceMethodInterceptor("myAspectJExpressionAdvisor")
    );
  }
}
